package com.itheima.exam;

import java.io.*;
import java.util.*;

public class test01 {
    public static void main(String[] args) throws IOException {
        Scanner sc=new Scanner(System.in);
        TreeSet<Score> ts=new TreeSet<>(new Comparator<Score>() {
            @Override
            public int compare(Score o1, Score o2) {
                int result=o2.getSum()-o1.getSum();
                return result;
            }
        });

        for (int i=1;i<=3;i++) {
            System.out.println("请输入第" + i + "名学生信息");
            System.out.println("姓名");
            String name=sc.next();
            System.out.println("语文成绩");
            int chinese = sc.nextInt();
            System.out.println("数学成绩");
            int math = sc.nextInt();
            System.out.println("英语成绩");
            int english = sc.nextInt();
            Score score = new Score(name,chinese,math,english);
            ts.add(score);
        }
        BufferedWriter bw = new BufferedWriter(new FileWriter("exam\\score.txt"));
        for (Score t : ts) {
            bw.write(t.getName()+","+t.getChinese()+","+t.getMath()+","+t.getEnglish());
            bw.newLine();
            bw.flush();
        }
        BufferedReader br=new BufferedReader(new FileReader("exam\\score.txt"));
        String line;
        while ((line=br.readLine())!=null) {
            System.out.println(line);
        }
    }
}
